//
//  TimeLineCell.m
//  QinzTimeLine
//
//  Created by Qinz on 2017/5/23.
//  Copyright © 2017年 Qinz. All rights reserved.
//

#import "TimeLineCell.h"
#import "SDAutoLayout.h"

@interface TimeLineCell ()

@property (weak, nonatomic) IBOutlet UILabel *ttimeLB;
@property (weak, nonatomic) IBOutlet UILabel *titleLB;
@property (weak, nonatomic) IBOutlet UILabel *typeLB;

@end

@implementation TimeLineCell

+ (instancetype) timeLineCell:(UITableView *) tableView{
    TimeLineCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TimeLineCell"];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"TimeLineCell" owner:nil options:nil] firstObject];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = UIColor.clearColor;
    }
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    self.pointView.sd_layout.topSpaceToView(self.contentView, 20).leftSpaceToView(self.contentView, 5).widthIs(12).heightEqualToWidth();
    self.pointView.sd_cornerRadius = @(6);
    
    self.lineView.sd_layout.topSpaceToView(self.pointView, 0).centerXEqualToView(self.pointView).widthIs(2).heightIs(50);//bottomSpaceToView(self.contentView, 0);
    self.ttimeLB.sd_layout.centerYEqualToView(self.pointView).leftSpaceToView(self.pointView, 10).rightSpaceToView(self.contentView, 240).heightIs(20);
    
    self.titleLB.sd_layout.centerYEqualToView(self.pointView).leftSpaceToView(self.ttimeLB, 10).rightSpaceToView(self.contentView, 100).heightIs(20);
    
    self.typeLB.sd_layout.centerYEqualToView(self.pointView).leftSpaceToView(self.titleLB, 30).rightSpaceToView(self.contentView, 20).heightIs(25);
    //self.titleLB.sd_layout.topSpaceToView(self.ttimeLB, 15).leftEqualToView(self.ttimeLB).rightSpaceToView(self.contentView, 10).autoHeightRatio(0);
}

-(void)setModel:(TimeLineModel *)model{

    _model = model;
    self.titleLB.text=  model.title;
    self.titleLB.textColor = [UIColor colorWithRed:128.0/255 green:138.0/255 blue:135.0/255 alpha:1];
    self.ttimeLB.text = model.time;
    self.ttimeLB.textColor = [UIColor colorWithRed:116.0/255 green:104.0/255 blue:190.0/255 alpha:1];
    self.typeLB.text = model.type;
    if ([self.typeLB.text isEqualToString:@"日常"]) {
        self.typeLB.textColor = [UIColor colorWithRed:34.0/255 green:139.0/255 blue:34.0/255 alpha:1];
        self.typeLB.backgroundColor = [UIColor colorWithRed:189.0/255 green:252.0/255 blue:201.0/255 alpha:1];
    }
    else if ([self.typeLB.text isEqualToString:@"单次"]) {
        self.typeLB.textColor = [UIColor colorWithRed:116.0/255 green:104.0/255 blue:190.0/255 alpha:1];
        self.typeLB.backgroundColor = [UIColor colorWithRed:116.0/255 green:104.0/255 blue:190.0/255 alpha:0.2];
    }
    else {
        self.typeLB.textColor = [UIColor colorWithRed:30.0/255 green:144.0/255 blue:255.0/255 alpha:1];
        self.typeLB.backgroundColor = [UIColor colorWithRed:30.0/255 green:144.0/255 blue:255.0/255 alpha:0.2];
    }
    
    self.typeLB.layer.cornerRadius = 12.5;
    self.typeLB.layer.masksToBounds = YES;

    [self setupAutoHeightWithBottomView:self.titleLB bottomMargin:0];
}

@end
